package com.example.books;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.books.tools.GetResoures;

public class ReadActivity extends AppCompatActivity implements View.OnClickListener {

    private TextView text_read;
    private Button back;
    private Button next;
    private String s="";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_read);
        initView();
    }

    private void initView() {
        text_read = (TextView) findViewById(R.id.text_read);
        Intent intent = getIntent();
        String path = intent.getStringExtra("path");
        s = countStr(GetResoures.GetBook(ReadActivity.this, path));
        back = (Button) findViewById(R.id.back);
        back.setOnClickListener(this);
        next = (Button) findViewById(R.id.next);
        next.setOnClickListener(this);
    }
    /**
     * 解析章节
     * @param str1
     * @return
     */
    public  String countStr(String str1) {
        if (str1.indexOf("------------") == -1) {
            text_read.setText(str1);
            return str1;
        } else{
            String str2=str1.substring(str1.indexOf("------------") + "------------".length());
            text_read.setText(str2.substring(0,str2.indexOf("------------") + "------------".length()));
            return str2;
        }
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.back:
                s = countStr(s);
                break;
            case R.id.next:
                s = countStr(s);
                break;
        }
    }
}
